package com.bh.web.controller.shipment;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.shipment.domain.JcShipmentTemplate;
import com.bh.shipment.service.IJcShipmentTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运单模板Controller
 * 
 * @author slx
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/shipment/template")
public class JcShipmentTemplateController extends BaseController
{
    @Autowired
    private IJcShipmentTemplateService jcShipmentTemplateService;

    /**
     * 查询运单模板列表
     */
    @ApiOperation("查询运单模板列表")
    @PreAuthorize("@ss.hasPermi('shipment:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcShipmentTemplate jcShipmentTemplate)
    {
        startPage();
        List<JcShipmentTemplate> list = jcShipmentTemplateService.selectJcShipmentTemplateList(jcShipmentTemplate);
        return getDataTable(list);
    }

    /**
     * 导出运单模板列表
     */
    @PreAuthorize("@ss.hasPermi('shipment:template:export')")
    @Log(title = "运单模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcShipmentTemplate jcShipmentTemplate)
    {
        List<JcShipmentTemplate> list = jcShipmentTemplateService.selectJcShipmentTemplateList(jcShipmentTemplate);
        ExcelUtil<JcShipmentTemplate> util = new ExcelUtil<JcShipmentTemplate>(JcShipmentTemplate.class);
        util.exportExcel(response, list, "运单模板数据");
    }

    /**
     * 获取运单模板详细信息
     */
    @ApiOperation("获取运单模板详细信息")
    @PreAuthorize("@ss.hasPermi('shipment:template:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcShipmentTemplateService.selectJcShipmentTemplateById(id));
    }

    /**
     * 新增运单模板
     */
    @ApiOperation("新增运单模板")
    @PreAuthorize("@ss.hasPermi('shipment:template:add')")
    @Log(title = "运单模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcShipmentTemplate jcShipmentTemplate)
    {
        jcShipmentTemplate.setJcOrganizationId(getOrgId());
        return toAjax(jcShipmentTemplateService.insertJcShipmentTemplate(jcShipmentTemplate));
    }

    /**
     * 修改运单模板
     */
    @ApiOperation("修改运单模板")
    @PreAuthorize("@ss.hasPermi('shipment:template:edit')")
    @Log(title = "运单模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcShipmentTemplate jcShipmentTemplate)
    {
        return toAjax(jcShipmentTemplateService.updateJcShipmentTemplate(jcShipmentTemplate));
    }

    /**
     * 删除运单模板
     */
    @ApiOperation("删除运单模板")
    @PreAuthorize("@ss.hasPermi('shipment:template:remove')")
    @Log(title = "运单模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcShipmentTemplateService.deleteJcShipmentTemplateByIds(ids));
    }
}
